package com.ruoyi.syf.handler.deleteChain.chainHandler;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.syf.domain.RiskCheckTask;
import com.ruoyi.syf.handler.deleteChain.DeleteChainHandler;
import com.ruoyi.syf.service.IRiskCheckTaskService;
import com.ruoyi.syf.service.IRiskMeasureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MeasureHandle extends DeleteChainHandler {

    @Autowired
    private IRiskMeasureService measureService;
    @Autowired
    private IRiskCheckTaskService taskService;

    @Override
    public void handleDelete(List<Long> ids) {
        //删除管控措施
        measureService.deleteRiskMeasureByIds(ids.toArray(new Long[0]));
        if (nextHandler != null) {
            //查询排查任务
            List<RiskCheckTask> list = taskService.list(new LambdaQueryWrapper<RiskCheckTask>().in(RiskCheckTask::getMeasureId, ids));
            if (!list.isEmpty()){
                nextHandler.handleDelete(list.stream().map(RiskCheckTask::getId).collect(Collectors.toList()));
            }
        }
    }
}
